import axios from 'axios'
import{history} from 'umi'
function GetUserToken(){
    return localStorage.getItem('token')
}
const Services = axios.create({
    // baseURL:'http://192.168.72.28:7001/api/v2',
    baseURL:'http://186s655f25.imwork.net/api/v2',
    timeout:5000
})
Services.interceptors.request.use(config=>{
    if(GetUserToken()){
        config.headers["_token"] = GetUserToken();
        config.headers['ContentType'] = 'application/json;charset=utf-8'
    }
    return config
},
error=>{
    return Promise.reject(error)
})

Services.interceptors.response.use(response=>{
    const result = response.data
    return result
},
error=>{
    if(error.response){
        console.log(response)
        switch(error.response.status){
            case 50010:
                history.push('/login')
                break
            case 50012:
                history.push('/login')
                break 
            case 50013:
                history.push('/login')
                break        }
    }
})


export default Services